package
{
	import com.uyaer.engine.Const;
	import com.uyaer.engine.Engine;
	import com.uyaer.engine.core.Bean;
	import com.uyaer.engine.core.Model;
	import com.uyaer.engine.display.Card;
	import com.uyaer.engine.display.Icon;
	import com.uyaer.engine.display.el.DynamicSprite;
	import com.uyaer.engine.event.EventManager;
	import com.uyaer.engine.event.EventType;
	import com.uyaer.engine.event.MyEvent;
	import com.uyaer.engine.loader.LoaderManager;
	import com.uyaer.engine.loader.MyLoaderInfo;
	import com.uyaer.engine.plug.JSON;
	import com.uyaer.engine.role.MyRole;
	import com.uyaer.engine.role.RolesManager;
	import com.uyaer.engine.text.TextCache;
	import com.uyaer.engine.utils.GetObject;
	import com.uyaer.engine.utils.HashMap;
	import com.uyaer.engine.utils.Point3D;
	import com.uyaer.engine.utils.Transform;
	import com.uyaer.engine.utils.Utils;
	import com.uyaer.engine.vo.GameObject;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Graphics;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.net.sendToURL;
	import flash.system.System;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	public class demo extends Sprite
	{
		private var engine:Engine;
		private var role:MyRole;
		private var rect:Sprite = new Sprite();
		private var debugTF:TextField = new TextField();
		public function demo()
		{
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			debugTF.autoSize = TextFieldAutoSize.LEFT;
			stage.addChild(debugTF);
			engine = Engine.instance.start(stage);
			addBg();
			addRole();
			EventManager.addEvent(EventType.ASECOND,onAsecond);
		}
		
		private function onAsecond(e:MyEvent):void{
			debugTF.text = "fps: " + engine.ticker.fps
							+ "\ntotal Memory :"+System.totalMemory/1024/1024+"M";
		}
		
		private function addBg():void{
			engine.scene.changeScene(null);
		}
		
		private function addRole():void{
			var bean:GameObject = new GameObject();
			bean.id = 1002;
			bean.defaultState = "stand";
			bean.resType =  "png";
			bean.resName = "person";
			bean.totalFrames = 32;
			bean.viewType = 2;
			var m:Model;
			for(var i:int  = 0 ; i < 250 ; i++){
				m = new Model(bean);
				m.x = Utils.rangInt(0,1100);
				m.y = Utils.rangInt(100,550);
				m.z_axis = m.y;
				RolesManager.instance.addModel(m);
			}
			var bean2:GameObject = new GameObject();
			bean2.id = 1001;
			bean2.defaultState = "stand";
			bean2.resType =  "png";
			bean2.resName = "person";
			bean2.totalFrames = 32;
			bean2.viewType = 2;
			bean2.pType = 2;
			m = new MyRole(bean2);
			m.x = 300;
			m.y = 200;
			m.z_axis = 200;
			RolesManager.instance.addModel(m);
		}
		
//		private function addRole():void{
//			LoaderManager.instance.add(new MyLoaderInfo("res/person.png",ss));
//		}
//		
//		private function ss(display:DisplayObject):void{
//			var bmd:BitmapData = (display as Bitmap).bitmapData;
//			LoaderManager.instance.loadBinary(new MyLoaderInfo("res/person.json",sss) , bmd.clone());
//			bmd.dispose();
//		}
//		private var list:Vector.<DynamicSprite> = new Vector.<DynamicSprite>();
//		private function sss(data:String ,bmd:BitmapData):void{
//			TextCache.texturePacker.putAll(Utils.texturePacker(data));
//			var arr:Array = TextCache.texturePacker.getKeys();
//			var name:int = 1001;
//			for(var i:uint = 0 ; i < 250 ; i ++){
//				name = Math.random()<0.5?1001:1002
//				var mc:DynamicSprite = new DynamicSprite(name+"_stand",32,bmd);
//				mc.y = 250+Math.random()*300;
//				mc.x = 800*Math.random()+100;
//				engine.scene.personCon.addChild(mc);
//				list.push(mc);
//			}
//			engine.ticker.addRefresh(ssss);
//		}
//		
//		private function ssss():void{
//			for each (var e:DynamicSprite in list) 
//			{
//				e.render();
//			}
//		}
	}
}